//
//  yxpColorSelectionVC.m
//  TestProject
//
//  Created by 杨小平 on 14-8-31.
//  Copyright (c) 2014年 yangxiaoping. All rights reserved.
//

#import "yxpColorSelectionVC.h"
#import "ColorColletionViewCell.h"

#define  _CELL @"acell"

@interface yxpColorSelectionVC ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{
    UICollectionView *_collectionView;
}

@end

@implementation yxpColorSelectionVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    
    _collectionView=[[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
    _collectionView.backgroundColor=[UIColor whiteColor];
    [_collectionView registerClass:[ColorColletionViewCell class] forCellWithReuseIdentifier:_CELL];
    _collectionView.showsVerticalScrollIndicator=NO;
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
    [self.view addSubview:_collectionView];
    
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(updateColorView)];
    
}
- (void)updateColorView
{
    [_collectionView reloadData];
}
#pragma mark -- UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 60.0;
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return NO;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ColorColletionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:_CELL forIndexPath:indexPath];
    
    float R=arc4random()%255;
    float G=arc4random()%255;
    float B=arc4random()%255;
    
    cell.colorView.backgroundColor=kColor(R, G, B);
    
    cell.RLabel.text=[NSString stringWithFormat:@"R:%.1f",R];
    cell.GLabel.text=[NSString stringWithFormat:@"G:%.1f",G];
    cell.BLabel.text=[NSString stringWithFormat:@"B:%.1f",B];
    
    return  cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CELL_SIZE;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
